package com.perceptivesoftware.licensing.client.dialogs.useradmin.plugin.user;

import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.perceptivesoftware.licensing.client.dialogs.useradmin.SecurityManagerView;

public class UserView extends SecurityManagerView {

	LayoutContainer layoutContainer = new LayoutContainer();
	private TabPanel tabPanel = new TabPanel();
	private boolean visible = true;
	private boolean superAdmin = true;
	private final UserSettingsTabItem userSettingsTab;
	private final ContentPanel permissionsController;

	UserView(ContentPanel permissionsController, UserSettingsTabItem userSettingsTab) {
		super();
		this.userSettingsTab = userSettingsTab;
		this.permissionsController = permissionsController;
		final TabItem permissionsTabItem = new TabItem("Permissions");
		permissionsTabItem.add(this.permissionsController);
		tabPanel.add(permissionsTabItem);
		tabPanel.add(this.userSettingsTab);
		layoutContainer.setLayout(new FitLayout());
		layoutContainer.add(tabPanel);
		superAdmin = false;
		initComponent(layoutContainer);
	}

	public void hidePermissionsPanel() {
		visible = true;
		layoutContainer.removeAll();
		tabPanel = new TabPanel();
		tabPanel.add(userSettingsTab);
		layoutContainer.add(tabPanel);
		superAdmin = true;
	}

	public void showPermissionsPanel() {
		layoutContainer.removeAll();
		visible = true;
		tabPanel = new TabPanel();
		final TabItem permissionsTabItem = new TabItem("Permissions");
		permissionsTabItem.setLayout(new FitLayout());
		permissionsTabItem.add(permissionsController);
		tabPanel.add(permissionsTabItem);
		tabPanel.add(userSettingsTab);
		layoutContainer.add(tabPanel);
		superAdmin = false;
	}

	@Override
	public String getName() {
		return "User Editor";
	}

	public boolean isUserViewVisible() {
		return visible;
	}

	public boolean isSuperAdmin() {
		return superAdmin;
	}
}
